/*
 * Copyright (C) 2009 Rafael Fernandes
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.phonebooksharing.android.widgets.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Paint.Style;
import android.util.AttributeSet;
import android.widget.LinearLayout;

import com.phonebooksharing.android.R;

public class BoxContainerView extends LinearLayout 
{ 
    protected Paint   innerPaint, borderPaint ;
    private int roundCorder;//default
    
    public BoxContainerView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(attrs);
    }

    protected void init(AttributeSet attrs) {
        
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.BoxContainerView);
        roundCorder = a.getInt(R.styleable.BoxContainerView_roundCorner, 5);
        
        innerPaint = new Paint();
        innerPaint.setColor(a.getColor(R.styleable.BoxContainerView_backgroundColor, 0xFF000000));
        innerPaint.setAntiAlias(true);

        borderPaint = new Paint();
        borderPaint.setColor(a.getColor(R.styleable.BoxContainerView_borderColor, 0xFF000000));
        borderPaint.setAntiAlias(true);
        borderPaint.setStyle(Style.STROKE);
        borderPaint.setStrokeWidth(a.getInt(R.styleable.BoxContainerView_borderThickness, 2));
    }
    
    public void setInnerPaint(Paint innerPaint) {
        this.innerPaint = innerPaint;
    }

    public void setBorderPaint(Paint borderPaint) {
        this.borderPaint = borderPaint;
    }
    
    @Override
    protected void dispatchDraw(Canvas canvas) {
        
        RectF drawRect = new RectF();
        drawRect.set(0, 0, getMeasuredWidth(), getMeasuredHeight());
        
        canvas.drawRoundRect(drawRect, roundCorder, roundCorder, innerPaint);
        canvas.drawRoundRect(drawRect, roundCorder, roundCorder, borderPaint);
        
        super.dispatchDraw(canvas);
    }
}